import axios from "axios";
import {nanoid} from "nanoid";

export default {
    namespaced:true,
    actions: {
        addPersonAsServer(context,value){
            axios.get('http://api.uixsj.cn/hitokoto/get').then(
                response=>{
                    context.commit('addPerson',{id:nanoid(),name:response.data})
                },
                error=>{
                    alert(error.message)
                }
            )
        }
    },
    mutations:{
        addPerson(state,value) {
            state.persons.unshift(value)
        }
    },
    state:{
        persons:[
            {id:'001',name:'张三'}
        ]
    }
}